package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.publish.domain.RecommendColumn;
import com.ruoyi.publish.service.RecommendColumnService;
import net.sf.jsqlparser.schema.Column;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/publish/recommend")
public class RecommendColumnController extends BaseController {
    @Autowired
    private RecommendColumnService recommendColumnService;
    @GetMapping
    public TableDataInfo list(RecommendColumn recommendColumn){
        startPage();
        List<RecommendColumn> recommendColumnList=recommendColumnService.selectRecommend(recommendColumn);
        return getDataTable(recommendColumnList);
    }
    //添加
    @PostMapping
    public AjaxResult add(@RequestBody RecommendColumn recommendColumn){
        System.out.println("新增推荐栏目参数：" + recommendColumn);
        recommendColumn.setCreateBy(SecurityUtils.getUsername());
        return toAjax(recommendColumnService.insert(recommendColumn));
    }
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody RecommendColumn recommendColumn){
        recommendColumn.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(recommendColumnService.update(recommendColumn));
    }
    @DeleteMapping("/{recommendId}")
    public AjaxResult delete(@PathVariable Long recommendId){
        return toAjax(recommendColumnService.deleteById(recommendId));

    }
    //查询栏目名
    @GetMapping("/columnName")
    public AjaxResult selectColumn(){
        return AjaxResult.success(recommendColumnService.selectColumnName());
    }
    //子栏目
    @GetMapping("/selectChildColumn")
    public AjaxResult selectChildColumn(@RequestParam Long parentId){
        List<RecommendColumn> recommendColumnList=recommendColumnService.selectChildColumn(parentId);
        return AjaxResult.success(recommendColumnList);
    }
    //
    @GetMapping("/availableSecondLevelColumns")
    public AjaxResult availableSecondLevelColumns(@RequestParam Long parentId) {
        List<Column> columns = recommendColumnService.selectAvailableSecondLevelColumns(parentId);
        return AjaxResult.success(columns);
    }



}
